Skip to content

Conversation

@da-viper
Copy link
Contributor

@da-viper da-viper commented Apr 6, 2025

dap console does not recognise expr as a command because it is not explicitly set.

It works fine in normal lldb because it is gotten from approximate match which is not available in the SBAPI

dap console does not recognise `expr` as a command because it is not explicitly set.

It works fine in normal lldb because it is gotten from approximate match which is not available in the SBAPI
@da-viper da-viper requested a review from JDevlieghere as a code owner April 6, 2025 21:41
@llvmbot llvmbot added the lldb label Apr 6, 2025
@llvmbot
Copy link
Member

llvmbot commented Apr 6, 2025

@llvm/pr-subscribers-lldb

Author: Ebuka Ezike (da-viper)

Changes

dap console does not recognise expr as a command because it is not explicitly set.

It works fine in normal lldb because it is gotten from approximate match which is not available in the SBAPI


Full diff: https://github.com/llvm/llvm-project/pull/134562.diff

1 Files Affected:

  • (modified) lldb/source/Interpreter/CommandInterpreter.cpp (+4-1)
diff --git a/lldb/source/Interpreter/CommandInterpreter.cpp b/lldb/source/Interpreter/CommandInterpreter.cpp
index 112d2f20fda41..a4071f5f0a602 100644
--- a/lldb/source/Interpreter/CommandInterpreter.cpp
+++ b/lldb/source/Interpreter/CommandInterpreter.cpp
@@ -444,6 +444,7 @@ void CommandInterpreter::Initialize() {
   if (cmd_obj_sp) {
     // Ensure `e` runs `expression`.
     AddAlias("e", cmd_obj_sp);
+    AddAlias("expr", cmd_obj_sp);
     AddAlias("call", cmd_obj_sp, "--")->SetHelpLong("");
     CommandAlias *parray_alias =
         AddAlias("parray", cmd_obj_sp, "--element-count %1 --");
@@ -1376,7 +1377,9 @@ bool CommandInterpreter::GetAliasFullName(llvm::StringRef cmd,
 }
 
 bool CommandInterpreter::AliasExists(llvm::StringRef cmd) const {
-  return m_alias_dict.find(cmd) != m_alias_dict.end();
+  std::string alias_name;
+  return GetAliasFullName(cmd, alias_name);
+  // return m_alias_dict.find(cmd) != m_alias_dict.end();
 }
 
 bool CommandInterpreter::UserCommandExists(llvm::StringRef cmd) const {

dap console does not recognise `expr` as a command because it is not explicitly set.

It works fine in normal lldb because it is gotten from approximate match which is not available in the SBAPI
@jimingham
Copy link
Collaborator

The lldb command line was designed so that it always does shortest complete match, and there are a lot of common commands that people only type partially. Adding one more expr alias isn't such a big deal, but adding special purpose aliases for all the shortenings people want to use is not supportable (and might collide with other aliases users have set).
So we need a better solution to this DAP problem than just adding aliases.

@da-viper
Copy link
Contributor Author

da-viper commented Apr 7, 2025

Another solution I could think of is prioritising, the repl command type instead of the repl variable type.
in

// Variables take preference to commands in auto, since commands can always
// be called using the command_escape_prefix
return term_is_variable ? ReplMode::Variable
: term_is_command ? ReplMode::Command
: ReplMode::Variable;
}

or add the previously defined aliases in docs explicitly as aliases.

@da-viper
Copy link
Contributor Author

So we need a better solution to this DAP problem than just adding aliases.
How about for aliases that are mentioned in the documentation, we explicitly set those as aliases.

@jimingham
Copy link
Collaborator

jimingham commented Apr 14, 2025

We may use the word expr in documentation, but that doesn't mean that a user could decide they wanted to use expr for something completely different. And even if we added an explicit alias for expr someone who was using it for another purpose will just get a little annoyed, then do:

command unalias expr
command alias expr <whatever it was before>

So it doesn't seem wise for DAP to depend on the fixed meaning of aliases.

@walter-erquinigo
Copy link
Member

@da-viper , I'm a bit surprised by this. Which mode are you using for the debug console?
I remember that in Variable mode (or whichever is the default), I was able to type :expr <something> and that worked.

Is your problem occurring in the Auto mode? I think that in this case, using a prefix like : should be enough to disambiguate. What do you think?

Adding aliases is error prone because there may be people who use expre instead of expr and then this logic breaks.

@da-viper
Copy link
Contributor Author

I am using what is the default. which is automode.

image

I am not sure if there is a way to change the mode from the user.

@walter-erquinigo
Copy link
Member

Probably the default is Auto. I guess we should add an option in the typescript code for selecting the mode.

And about :, I confused you because I set up my debugger to use : instead of a backtick.

In this mode, I think it would be great to determine via a quick parsing if the input string is an actual expression or not. What would be nice would be do this:

  • If the input string consists of at least two words, then run some quick command parsing to see if it's valid or not. If it's valid, then execute it as a command, otherwise follow the existing code path

what do you think?

@da-viper da-viper closed this Jun 3, 2025
@da-viper da-viper deleted the fix-expr-alias-in-lldb-dap-console branch September 30, 2025 15:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants